package com.riddle.admin.controller;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.ResponseBody;
import com.riddle.model.Menu;
import com.riddle.service.BaseService;
import com.riddle.service.MenuService;
import com.riddle.util.JsonUtil;
import com.riddle.util.StringUtil;
import com.riddle.vmodel.PageModel;
import com.riddle.vmodel.QueryModel;
import com.riddle.vmodel.VMsg;

@Controller
@RequestMapping("/admin/menu")
public class MenuController extends BaseController<Menu> {

	@Resource
	private MenuService menuService;
	
	@RequestMapping()
	public ModelAndView index() {
		return new ModelAndView("admin/menu/index");
	}
	
	@RequestMapping("/leftmenu")
	public ModelAndView leftmenu() {
		List<Menu> list = menuService.queryModelByPage(null, null, null);
		return new ModelAndView("admin/menu/leftmenu", "menus", list);
	}
	
	protected BaseService getService() {
		return menuService;
	}
	
	@RequestMapping(value="/list", produces="application/json;charset=utf-8")
	@ResponseBody
	public String list(QueryModel queryModel) {
		return super.list(queryModel);
	}
	
	@RequestMapping("/add")
	public String add() {
		return "admin/menu/add";
	}
	
	@RequestMapping(value="/addmodel", produces="application/json;charset=utf-8")
	@ResponseBody
	public String addModel(Menu menu) {
		return super.addModel(menu);
	}
	
	@RequestMapping("/modify")
	public ModelAndView modify(Long id) {
		Menu menu = menuService.query(id);
		return new ModelAndView("admin/menu/modify", "menu", menu);
	}
	
	@RequestMapping(value="/modifymodel", produces="application/json;charset=utf-8")
	@ResponseBody
	public String modifyModel(Menu menu) {
		return super.modifyModel(menu);
	}
	
	@RequestMapping(value="/delete", produces="application/json;charset=utf-8")
	@ResponseBody
	public String delete(Long id) {
		return super.delete(id);
	}
	
	@RequestMapping(value="/getparentmodel", produces="application/json;charset=utf-8")
	@ResponseBody
	public String getParentModel() {
		return super.getParentModel();
	}
}
